package com.zyx.mysql.controller;

import com.zyx.mysql.mapper.generated.ProductMapper;
import com.zyx.mysql.model.Product;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDateTime;

/**
 * @Description: TODO
 * @Author ZYX
 * @Date 2021/11/24 21:19
 * @Version 1.0
 */
@RestController
@RequestMapping("/product")
public class ProductController {

    @Autowired
    private ProductMapper productMapper;

    @PostMapping("/add")
    public String insertProduct(){

        for (int i = 10000; i < 11000; i++) {
            Product product = new Product();
            product.setId(Long.valueOf(i));
            product.setSaleId(String.valueOf(i));
            product.setStoreId(Long.valueOf(i));
            product.setProductSeq("productSeq"+i);
            product.setSkuId("skuId"+i);
            product.setSpuId("spuId"+i);
            product.setValid(true);
            product.setCreateTime(LocalDateTime.now());
            product.setUpdateTime(LocalDateTime.now());

            int insert = productMapper.insert(product);

            product = null;
        }


        return "success";
    }

    @GetMapping("/get/{id}")
    public Product queryProduct(@PathVariable Long id){
        return productMapper.selectByPrimaryKey(id);
    }


}
